package com.qf.ssm.websocket;

import com.qf.ssm.event.PowerCommandEvent;
import com.qf.ssm.event.UpdateDevicesStatusEvent;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

import java.io.IOException;

@Component
public class PowerCommandHandler extends BaseControllHandler<PowerCommandEvent> implements BaseCheckStatusHandler{

    @Override
    public void onEvent(PowerCommandEvent event) throws IOException {
        super.onEvent(event);
    }

    @Override
    protected void onOpen(WebSocketSession session) {
        Object name = session.getAttributes().get("name");
        getContext().publishEvent(new UpdateDevicesStatusEvent((String) name, "1"));
    }

    @Override
    protected void onClose(WebSocketSession session) {
        Object name = session.getAttributes().get("name");
        getContext().publishEvent(new UpdateDevicesStatusEvent((String) name, "0"));
    }
}
